package com.mcppro.aidatabase.dto;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.util.List;
import java.util.Map;

/**
 * 数据库操作结果DTO
 * 
 * @author MCP Pro
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DatabaseOperationResult {

    /**
     * 操作是否成功
     */
    private boolean success;

    /**
     * 操作类型
     */
    private String operation;

    /**
     * 执行的SQL语句
     */
    private String executedSql;

    /**
     * 查询结果数据
     */
    private List<Map<String, Object>> data;

    /**
     * 影响的行数
     */
    private int affectedRows;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 执行时间（毫秒）
     */
    private long executionTimeMs;

    /**
     * 总记录数（用于分页）
     */
    private Long totalCount;

    /**
     * 额外信息
     */
    private Map<String, Object> metadata;

    /**
     * 创建成功结果
     */
    public static DatabaseOperationResult success(String operation, String sql, 
                                                  List<Map<String, Object>> data, 
                                                  int affectedRows, 
                                                  long executionTime) {
        DatabaseOperationResult result = new DatabaseOperationResult();
        result.setSuccess(true);
        result.setOperation(operation);
        result.setExecutedSql(sql);
        result.setData(data);
        result.setAffectedRows(affectedRows);
        result.setExecutionTimeMs(executionTime);
        return result;
    }

    /**
     * 创建失败结果
     */
    public static DatabaseOperationResult failure(String operation, String sql, 
                                                  String errorMessage, 
                                                  long executionTime) {
        DatabaseOperationResult result = new DatabaseOperationResult();
        result.setSuccess(false);
        result.setOperation(operation);
        result.setExecutedSql(sql);
        result.setErrorMessage(errorMessage);
        result.setExecutionTimeMs(executionTime);
        return result;
    }
}